// 注意：要删除本模块的require缓存，否则不支持热加载
delete require.cache[require.resolve('./student.js')];

const path = require('path');
const mockjs = require('mockjs');
const lowdb = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const db = lowdb(new FileSync(path.resolve(__dirname, '../json/student.json')));
const _ = db._;

export function create(data) {
    const user = _.assign(data, {
        id: mockjs.Random.guid()
    })
    let len = db.get('list').find({ name: user.name }).length
    if (len && len == 1) {
        return;
    }
    db.get('list')
        .push(user)
        .write();
}
export function getAll() {
    let data = db.get('list').value();
    return data;
}
